I want a trigger such that when an attribute value changes in Module 1, it should trigger an object creation in Module 2 and the text from the Module 1(for the corresponding object) should be copied to the newly created object in Module 2
|
Re: Trigger to create objects in another module
Louie was very helpful when I was trying to get triggers to work. He provided code that deploys a trigger on the current module that I have been using without any problems. I had been using a triggers to modify an enum and ran into massive problems that he helped me fix. You may find it helpful to search for "trigger enum". You want to write the code to execute when the trigger fires as a string, so you would have something like this string DXLcode = " // get some basic info about the trigger event Trigger firedTrig = current // capture the trigger which fired AttrDef ad = attrdef(firedTrig) // get the attribute that caused trigger to fire Object obj = object(firedTrig) // get object that caused trigger to fire Module mod = module(firedTrig) // get module in which trigger fired string s = \"example string\" // remember to escape all quotes when coding inside a string // code to create new object in module two // open module 2 for edit // Module mod2 = edit(...) // create and populate new object here. Im assuming you know how to do this (mainly because I don't remember the syntax or commands off the top of my head) but if you need help let me know //you will probably have something like this //newObj.\"Object Text\" = obj.\"Object Text\"\"\" // close and save module 2 // close(mod2, true) "
The following code is used to deploy/delete the trigger
// the following line is used to check the string DXLCode for errors. Errors are returned into the
// string ErrorMessag, if there are no errors, the function returns null
string ErrorMessage = checkDXL(DXLCode)
// print any error messages and halt code if there are errors
if (!null ErrorMessage){
print ErrorMessage"\n"
halt()
}
string trigName = "Trigger1" // name of trigger
// options for query box
string options = {"Deploy Trigger", "Delete Trigger", "Cancel"}
int mode = query("Trigger: " trigName, options)
if (mode == 0){ // deploy trigger
// first delete any trigger that has the same name (ie a previous version)
print "Deleting trigger " trigName"...\n"
ErrorMessage = delete(trigName, module->attribute, post, modify, 5)
// Deploy the trigger
// this particular example is for a post modify attribute trigger
print "Deploying trigger " trigName "...\n"
trg = trigger(trigName, module->attribute, post, modify, 5, DXLCode)
} else if (mode == 1) { // delete trigger
// delete the existing trigger
print "Deleting trigger " trigName"...\n"
ErrorMessage = delete(trigName, module->attribute, post, modify, 5)
} else { // cancel
print "Canceling...\n"
}
|
Re: Trigger to create objects in another module An easier approach may be to collect the data (''maybe by trigger''), then have someone create the new objects in periodically. |
Re: Trigger to create objects in another module If you post what you are trying to accomplish then some of the experienced Project Admins here will suggest a reasonable strategy. -Louie |